package cn.wuxun.sponsor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jt.common.pojo.Sponsor;
import com.jt.common.vo.EasyUIResult;
import com.jt.common.vo.SysResult;


import cn.wuxun.sponsor.service.SponsorService;

@RestController
@RequestMapping("sponsor")
public class SponsorController {
	@Autowired
	private SponsorService sponsorService;
	
	
	/**
	 * 功能：添加赞助商
	 * 
	 * @param sponsor
	 * @return SysResult  其结构为：Integer status： 200表示成功,其他表示失败；String msg;成功返回 “ok”,失败返回其他信息；Object data;根据需求携带其他数据
	 */
	@RequestMapping("addSponsor")
	public SysResult addSponsor(Sponsor sponsor){
		try {
			sponsorService.addSponsor(sponsor);
			return SysResult.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return SysResult.build(201, e.getMessage(), null);
		}	
	}
	
	@RequestMapping("updateSponsor")
	public SysResult updateSponsor(Sponsor sponsor){
		try {
			sponsorService.updateSponsor(sponsor);
			return SysResult.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return SysResult.build(201, e.getMessage(), null);
		}
	}
	
	@RequestMapping("querySponsor")
	public Sponsor querySponsorByID(int sid){
		Sponsor sponsor=sponsorService.querySponsorById(sid);
		return sponsor;
		
	}
	
	@RequestMapping("delSponsor")
	public SysResult delSponsor(int sid){
		try {
			sponsorService.delSponsor(sid);
			return SysResult.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return SysResult.build(201, e.getMessage(), null);
		}
	}
	
	@RequestMapping("querySponsorByPage")
	public EasyUIResult querySponsorByPage(Integer page,Integer rows){
		EasyUIResult result=sponsorService.querySponsorByPage(page,rows);
		
		return result;
	}
	
	@RequestMapping("queryAll")
	public List queryAllSponsor(){
		List<Sponsor>sponsorList=sponsorService.queryAllSponsor();
		return sponsorList;
	}
	
	
}	
